Repository navigation
Conversation
A second encoder on the stream Media Foundation already wrote rebases timestamps, and the mov muxer rejects the next packet. Co-authored-by: Kyzer <kyzer1023@users.noreply.github.com>
The software encoder stays on the existing stream and the take clock, so the next packet cannot move backwards. Co-authored-by: Kyzer <kyzer1023@users.noreply.github.com>
A static capture sends no new frames. The software loop was starting without the frame Media Foundation had been repeating, so those repeats encoded nothing until the screen changed.
|
@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
| assert!( | ||
| decoded.last_video_secs > 1.5, | ||
| "video timestamps restart at the switch, last pts {:.3}s", | ||
| decoded.last_video_secs | ||
| ); |
There was a problem hiding this comment.
The new test never checks video spacing or order. Checking that the largest video timestamp exceeds 1.5 seconds still passes if frames disappear around the switch or timestamps move backwards before recovering. Record consecutive video timestamps and assert their order, the largest gap across the switch, and the final difference between audio and video.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/enc-ffmpeg/src/video/mid_take.rs
Line: 85-89
Comment:
**Video gaps escape the test**
The new test never checks video spacing or order. Checking that the largest video timestamp exceeds 1.5 seconds still passes if frames disappear around the switch or timestamps move backwards before recovering. Record consecutive video timestamps and assert their order, the largest gap across the switch, and the final difference between audio and video.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed in 46ea27dd1: mid_take now records every video packet timestamp in order and asserts non-decreasing PTS, consecutive frame gaps (including across the switch) strictly under two frames, and final audio/video end-time diff within 100 ms.
| End, | ||
| } | ||
|
|
||
| /// A repeat encodes the frame already carried. An empty carry drops it. |
There was a problem hiding this comment.
This sentence restates the two cases implemented by frame_to_encode below. AGENTS.md explicitly bans comments that narrate what the code does. Remove it or explain a non-obvious constraint instead. This repository requirement must be satisfied before merging.
| /// A repeat encodes the frame already carried. An empty carry drops it. |
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/output_pipeline/frame_pacing.rs
Line: 31
Comment:
**Comment repeats the code**
This sentence restates the two cases implemented by `frame_to_encode` below. `AGENTS.md` explicitly bans comments that narrate what the code does. Remove it or explain a non-obvious constraint instead. This repository requirement must be satisfied before merging.
```suggestion
```
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Fixed in 46ea27dd1: removed the narrating doc comment on PacedPixels.
Record every video packet timestamp and reject a backwards step, a gap wider than two frames, or an audio and video ending more than 100ms apart. Drop the comment that restated frame_to_encode.
…pen ID 8 (CapSoftware#4495), run ID 12 on laptop
Summary
When the native Windows Media Foundation H.264 encoder stops mid-take in
WindowsMuxerorWindowsCameraMuxer, Cap currently fails the encoder task instead of continuing the recording. This PR switches tolibx264on the existing MP4 video stream and take clock so the take completes with continuous A/V.Changes
crates/enc-ffmpeg(base.rs,video/h264.rs,video/mid_take.rs): AddH264EncoderBuilder::build_software_on_stream(stream_index, last_stream_dts)andEncoderBase::continue_after(last_stream_dts)solibx264continues writing to the existing stream without rebasing timestamps backwards. Includes regression tests covering the mid-take H.264 stream swap (mid_take.rs).crates/mediafoundation-ffmpeg&crates/enc-mediafoundation: Expose the last written stream DTS across the Media Foundation muxer boundary and addEncoderFailureReason::Injecteddriven byCAP_MF_FAIL_AFTER_FRAMESfor reproducible mid-take failure testing.crates/recording(output_pipeline/win.rs,output_pipeline/frame_pacing.rs): On Media Foundation runtime failure inWindowsMuxerandWindowsCameraMuxer, openlibx264on the same stream, emitPipelineHealthEvent::EncoderRebuilt, and carry the lastScreenFrameinto the software loop viaframe_pacing::frame_to_encodeso static-screen repeats continue without a multi-second gap across the switch.Verification
Tested on Windows 11 with an AMD Radeon 780M (
cap-gpui --releaseat12d98a072,CAP_MF_FAIL_AFTER_FRAMES=30for takes 1–2, unset for control; ~10.5 s Studio screen + audio takes):Complete, zeroERRORlogs, and playable video/audio.Media Foundation H264 stopped mid-take; switching to libx264atframes_encoded=30and contain thex264 - core 164SEI header; the control does not.12d98a072) to 0.1333 s.CAP_MF_FAIL_AFTER_FRAMES=30(on AMD, Media Foundation is skipped unless the env hook is active). NVIDIA and Intel Windows hardware were not tested locally.

Confidence Score: 5/5
The PR appears safe to merge, with both previous findings addressed.Summary
The PR lets Windows screen and camera recordings switch from Media Foundation to
libx264without restarting the video timeline.Reviews (2) · Last reviewed commit: "test: bound video spacing across the mid..." · Reviewed by Greptile